import React from 'react';
import { Button, Checkbox, Form, Input } from 'antd';
import request from '../../api/request'
import { useNavigate } from 'react-router-dom';
import style from '../login/index.module.css'
import { UserOutlined ,ShoppingOutlined} from '@ant-design/icons';
import { useDispatch } from 'react-redux';
import { username } from '../../store/user';
function Index() {
    const nav=useNavigate()
    const dispatch=useDispatch()
    const onFinish = values => {
  console.log('Success:', values);
  request.post('/login',values).then((res)=>{
        localStorage.setItem('token',res.data.token)
        localStorage.setItem('username',res.data.username)
        alert('登录成功')
        nav('/home')
        dispatch(username(res.data))
  })
};
const onFinishFailed = errorInfo => {
  console.log('Failed:', errorInfo);
};
  return (
    <div className={style.op}>
        <div className={style.pp}>
  <Form
    name="basic"
    labelCol={{ span: 8 }}
    wrapperCol={{ span: 16 }}
    style={{ maxWidth: 600 }}
    initialValues={{ remember: true }}
    onFinish={onFinish}
    onFinishFailed={onFinishFailed}
    autoComplete="off"
  >
    <Form.Item
      label=""
      name="account"
     rules={[{ required: true, message: '请输入正确的用户名' }]}
    >
      <Input  prefix={<UserOutlined />}/>
    </Form.Item>

    <Form.Item
      label=""
      name="password"
    rules={[{ required: true, message: '请输入正确的密码' }]}
    >
      <Input.Password  prefix={<ShoppingOutlined />}/>
    </Form.Item>


    
      <p style={{color:'blue',marginLeft:'150px'}}>还没有登录账号?请立即登录</p>
   

    <Form.Item label={null}>
      <Button type="primary" htmlType="submit" >
      验证账号
      </Button>
    </Form.Item>
  </Form>
        </div>
 
    </div>
  )
}

export default Index
